package text.adventure.data;

import java.util.Map;

import text.adventure.blackboard.Blackboard;
import text.adventure.blackboard.Observer;


public class GameObject implements Observer {
	
	private Blackboard blackboard;
	private Map<String,Reaction> behavior;
	private Map<String,Integer> flags;
	private String id;
	
	public GameObject(){};
	
	public GameObject(String id) {
		this.id = id;
	}
	
	public GameObject(String id, Map<String,Reaction> behavior, Map<String,Integer> flags) {
		this.blackboard = Blackboard.getInstance();
		this.id = id;
		this.behavior = behavior;
		this.flags = flags; 
	}
	
	public boolean receive(TextCommand textc) {
		if(behavior.containsKey(textc.getVerb())) {
			return behavior.get(textc.getVerb()).run(textc.getTextObj(), blackboard);
		} else {
			return false;
		}
	}
	
	public int getFlag(String flagname, int status) { // 0 = not set, 1 = true, -1 = false
		if(flags.containsKey(flagname)) {
			if(flags.get(flagname) == 0) {
				return status;
			} else {
				return flags.get(flagname);
			}
		} else {
			return status;
		}
	}

	public void setBehavior(Map<String, Reaction> behavior) {
		this.behavior = behavior;
	}


	public void setFlags(Map<String, Integer> flags) {
		this.flags = flags;
	}
	
	public void addFlag(String flagname, int value) {
		flags.put(flagname,value);
	}

	public String getId() {
		return this.id;
	}
}